namespace Sharpmark.PerfectLife.BlogAssist
{
    using System;
    using System.Xml;
    using Sharpmark.PerfectLife.Core.HtmlDocument;

    class BlogHtmlGenerator
    {
        public static string CreateImageHtml(
            string href, string title, string rel,
            bool isOpenNewWindow,
            string src, string alt,
            int border, int width, int height,
            ImageAlignType align)
        {
            ImageGenerator img = new ImageGenerator();

            img.GenerateImageHtml(src, alt, border, width, height, align);

            LinkGenerator link = new LinkGenerator();
            link.GenerateLinkHtml(href, title, rel,
                isOpenNewWindow, img.ToString());

            return link.ToString();
        }

        public static string CreateLightBoxImageHtml(
            string src, string alt, string relname,
            bool isOpenNewWindows, int width, int height,
            ImageAlignType align)
        {
            return CreateImageHtml(
                src, alt, "lightbox[" + relname + "]",
                isOpenNewWindows, src, alt, 0, width, height, align);

        }

        public static string SplitImageUrl(string src)
        {
            //<a href="http://picasaweb.google.com/SharpMark/XiangshanPark/photo#5128141571014218194">
            //<img src="http://lh4.google.com/SharpMark/RyrRlro3UdI/AAAAAAAACCA/UCciq9CG8vE/s800/IMG_3215.JPG" />
            //</a>

            //src = "<a href=\"http://picasaweb.google.com/SharpMark/XiangshanPark/photo#5128141571014218194\"><img src=\"http://lh4.google.com/SharpMark/RyrRlro3UdI/AAAAAAAACCA/UCciq9CG8vE/s800/IMG_3215.JPG\" /></a>";
            XmlDocument xd = new XmlDocument();
            try
            {
                xd.LoadXml(src);

                return xd.ChildNodes[0].ChildNodes[0].Attributes[0].InnerText;
            }
            catch (Exception e)
            {
                string m = e.Message;
                return src;
            }
        }
    }
}
